package com.xcity.game.activity.newplayer.tracer;

import java.text.MessageFormat;

import com.xcity.game.activity.newplayer.NewPlayerDoingStr;
import com.xcity.game.activity.newplayer.NewPlayerTask;
import com.xcity.game.activity.newplayer.NewPlayerTracer;
import com.xcity.game.activity.newplayer.NewPlayerTracerLabel;
import com.xcity.game.battle.pve.PVEService;
import com.xcity.game.battle.pve.PVEStage;

@NewPlayerTracerLabel(NewPlayerTracer.NORMAL_STAGE_DONE)
public class NormalStageDoneTracer implements NewPlayerTracer {

	@Override
	public boolean isDone(NewPlayerTask task) {
		int[] params = task.getTemplate().getParam();
		int[] progress = task.getProgress();
		if(progress[0] >= params[0] && progress[1] == params[1] && progress[2] == params[2]){
			return true;
		}
		return false;
	}

	@Override
	public void onChange(NewPlayerTask task, Object... vals) {
		int stageA = 1;
		int stageB = 1;
		PVEStage stage = (PVEStage)vals[1];
		if(stage != null){
			stageA = stage.getTemplate().getPage();//从1开始//(tempid + PVEService.NUM_OF_PER_PAGE - 1) / PVEService.NUM_OF_PER_PAGE;
			stageB = stage.getSubIndex() + 1;//((tempid - 1) % PVEService.NUM_OF_PER_PAGE) + 1;
		}
		int[] params = task.getTemplate().getParam();
		int[] progress = task.getProgress();
		if(params[1] == stageA && params[2] == stageB){
			progress[0] = progress[0] + 1;
			progress[1] = params[1];
			progress[2] = params[2];
		}
	}

	@Override
	public String getDoingStr(NewPlayerTask task) {
		int[] params = task.getTemplate().getParam();
		if(params[0] == 1){
			return MessageFormat.format(NewPlayerDoingStr.STR_NORMAL_STAGE_DONE, params[1], params[2]);
		}
		return MessageFormat.format(NewPlayerDoingStr.STR_NORMAL_STAGE_DONE_MULTI, params[1], params[2], params[0]);
	}

}
